﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.DataVisualization.Charting;
using System.Drawing;

public partial class Controls_ucDiskSpace : System.Web.UI.UserControl
{
    public string DiskName { get; set; }
    public Int64 FreeSpace { get; set; }
    public Int64 TotalSpace { get; set; }

    protected void Page_Load(object sender, EventArgs e)
    {
        double r;
        try
        {
            r = ((double)FreeSpace / (double)TotalSpace) * 100;
        }
        catch
        {
            r = 0;
        }
        lblDiskName.Text = DiskName;
        lblFreeRatio.Text = String.Format("{0:0.00}%", r);
        try
        {
            Chart1.Series.Clear();
            Chart1.Series.Add("Series1");
            Chart1.Series["Series1"].ChartType = System.Web.UI.DataVisualization.Charting.SeriesChartType.Pie;
            Chart1.Series["Series1"].Points.AddY((double)FreeSpace);
            Chart1.Series["Series1"].Points[0].Color = (r > 30 ? Color.Green : Color.Red);
            Chart1.Series["Series1"].Points[0].Label = "Free";
            Chart1.Series["Series1"].Points.AddY((double)TotalSpace - (double)FreeSpace);
            Chart1.Series["Series1"].Points[1].Color = Color.Blue;
            Chart1.Series["Series1"].Points[1].Label = "Used";
            if (TotalSpace == 0)
            {
                this.Visible = false;
            }
        }
        catch { }
    }
}